﻿#ifndef CHARTPANE_H
#define CHARTPANE_H

#include <QtCharts>
QT_CHARTS_USE_NAMESPACE

#include <QWidget>
#include <QStandardItemModel>
#include <QItemSelectionModel>
#include "chartview/dealchartdata.h"
#include <QSplineSeries>

#define TM "TimePoint"

namespace Ui { class ChartPane; };

class ChartPane : public QWidget
{
    Q_OBJECT
public:

    enum BarOrientation
    {
        VERTICAL_BAR = 0,
        HORIZONTAL_BAR,
    };

    ChartPane(QWidget *parent = 0);
    ~ChartPane();


    bool getTabState(QString file);

    void setFile(QString file,int type);

    void drawLine();

    void drawBar();

    void drawSpline();

    void setData(const QMap<QString, QMap<QString, long long>>& barData);


    void setSplineData();


    void setLabels(const QStringList& labels);

    void setTitle(const QString& title);
    void setYLabel(const QString& yLabel);


    void setOrientation(BarOrientation orientation);


    void setPorssBarValue(int nData1, int nData2, int nDataMax2);

    void showUI();

    QChart* chart();

protected:

    void init();


    void clear();


    void clearChartUI();


    void dealData();

    QStringList autoGenLabels(const QMap<QString, QMap<QString, long long>>& data);

    void analyseData(const QMap<QString, QMap<QString, long long>>& data,
                     long long& minVlue, long long& maxValue);

    void buildModel(const QMap<QString, QMap<QString, long long>>& data,
                    const QStringList& labels, QStandardItemModel* model);

    QMap<QString, QMap<QString, long long>> m_chartData;

    QMap<double,double> m_chartSplineData;
    QMap<int, int> m_barDatas;
    int m_nMax;

    QStandardItemModel* m_model;
    QChart* m_chart;
    QString m_title;
    QString m_label;
    QStringList m_labels;
    long long m_minValue;
    long long m_maxValue;
    BarOrientation m_barOrientation;

private:
    Ui::ChartPane *ui;

    QBarSeries *curSeries;
    QHorizontalBarSeries *curHorSeries;
    QValueAxis *curAxis;

    QLineSeries *LineSeries;

    QString m_sFile;
    int m_nType;
public:
    int m_nIndex;
    int m_nRow;
    QVector<qint64> m_vIndexs;
    DealChartData m_dealData;

private slots:
    void on_btn_styleSet_clicked();

    void on_LegendMarkerClicked();

    void on_btnSetTitle_clicked();

    void on_btnSetTitleFont_clicked();

    void on_btnSetMargin_clicked();

    void on_chkBarLabelVisible_clicked(bool checked);

    void on_radioButton_middle_clicked();

    void on_radioButton_top_clicked();

    void on_radioButton_bottom_clicked();

    void on_radioButton_out_clicked();

    void on_chkLegendVisible_clicked(bool checked);

    void on_btnSetAxisRange_clicked();

    void on_spinTickCount_valueChanged(int arg1);

    void on_spinMinorTickCount_valueChanged(int arg1);

    void on_checkBox_clicked(bool checked);

    void on_chkGridLineVisible_clicked(bool checked);

    void on_chkMinorTickVisible_clicked(bool checked);

    void on_chkBoxLegendBackground_clicked(bool checked);

    void on_radioButton_clicked();

    void on_radioButton_2_clicked();

    void on_radioButton_3_clicked();

    void on_radioButton_4_clicked();

    void on_btnLegendFont_clicked();

    void on_btnLegendlabelColor_clicked();

    void on_chkBoxVisible_clicked(bool checked);

    void on_btnAxisSetTitle_clicked();

    void on_btnAxisSetTitleFont_clicked();

    void on_chkBoxAxisTitle_clicked(bool checked);

    void on_pushButton_clicked();

    void on_btnAxisLabelColor_clicked();

    void on_btnAxisLabelFont_clicked();

    void on_chkBoxLabelsVisible_clicked(bool checked);

    void on_btnGridLineColor_clicked();

    void on_pushButton_10_clicked();

    void on_chkAxisLineVisible_clicked(bool checked);

    void on_btnAxisLinePen_clicked();

    void on_btnAxisLinePenColor_clicked();

    void on_btnMinorColor_clicked();

    void on_btnMinorPen_clicked();

    void on_cBoxAnimation_currentIndexChanged(int index);

    void on_cBoxTheme_currentIndexChanged(int index);

    void on_actZoomIn_triggered();

    void on_actZoomOut_triggered();

    void on_actZoomReset_triggered();
    void on_btn_up_clicked();
    void on_btn_down_clicked();
};

#endif // CHARTPANE_H
